/*
 * @lc app=leetcode.cn id=1154 lang=typescript
 *
 * [1154] 一年中的第几天
 */

// @lc code=start
function dayOfYear(date: string): number {
    let list = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    const d = new Date(date);

    let addOne = 0;
    if (d.getMonth() > 1) {
        if (
            d.getFullYear() % 400 === 0 ||
            (d.getFullYear() % 4 === 0 && d.getFullYear() % 100)
        )
            addOne = 1;
    }
    return (
        list.slice(0, d.getMonth()).reduce((a, b) => a + b, 0) +
        d.getDate() +
        addOne
    );
}
// @lc code=end
